<?php
/**
 * diy获取商品相关
 * Created by PhpStorm.
 * User: 小蛮哼哼哼
 * Email: 243194993@qq.com
 * Date: 2022/4/13
 * Time: 17:00
 * motto: 现在的努力是为了小时候吹过的牛逼！
 */

namespace app\diy\controller;

use app\BaseController;
use app\common\lib\Show;
use app\common\lib\Status;
use app\common\model\MallCate;
use app\common\model\MallGoods;

class Goods extends BaseController
{
    /**
     * 获取商品分类
     * @return array|\think\response\Json
     */
    public function GoodsByCate()
    {
        //获取所有分类
        if (!$this->request->isGet()) {
            return Show::json_diy(Status::mini_error,"请求类型错误");
        }
        //获取分类
        try {
            $menu = (new MallCate())->getMallCateByPidList(0,'id as type ,title as name');
        } catch (\Exception $e) {
            return Show::json_diy(Status::mini_error,"分类异常");
        }

        return Show::json_diy(1,"ok",$menu);
    }
    public function GoodsCateById(){
        $cate_id = $this->request->param('cate_id',0,'intval');
        if($cate_id == 0){
            return Show::json_diy(0,"内部异常");
        }
        //查询分类下面的id
        /**
         * coverUrl:
        'https://imgs.starfirelink.com/minicourse/非遗传承人@2x_1621504834414.png',
        introduce: '',  //描述
        price: 0,
        name: '测试1',
        videoId: '5285890818212341060',
        id: 403,
        type: 2,
        seriesId: '0',
         */
        try {
            $row = (new MallGoods())->getMallGoodsByCateId($cate_id, 'id,logo as coverUrl,thumb_title as introduce,price,title as name,id as videoId,cate_id as type,sales as seriesId');
        }catch (\Exception $e){
            return Show::json_diy(0,"内部异常");
        }
        return Show::json_diy(1,"ok",$row);

    }
}